<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!--
Not Automatically generated, changed!:
$Id: script_ref_execution_model_sequence_events.htm,v 1.3 2010/11/28 18:47:26 wilbertd Exp $ 
-->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Scripting reference - The script execution model - Sequence of events</title>
<link rel="stylesheet" type="text/css" href="../avisynth.css">
</head>
<body>
<h2>The script execution model - Sequence of events</h2>
<p>The sequence of events that occur when you execute (ie load and render to
your favorite encoder) an AviSynth script is presented below. The sequence is
conseptualy divided in three major phases:</p>
<ol>
  <li><a href="#The_initialisation_phase">Initialisation phase</a></li>
  <li><a href="#The_script_loading_and_parsing_phase">Script loading and parsing
    phase</a></li>
  <li><a href="#The_video_frames_serving_phase">The video frames serving phase</a></li>
</ol>
<a name="The_initialisation_phase"></a>
<h3><span class="mw-headline">The initialisation phase</span></h3>
<p>During this phase the following events occur:</p>
<ul>
  <li>An AVI stream object is created by the operating system, using the handler
    code provided by AviSynth.</li>
  <li>AviSynth dll is loaded and performs (among other initialization actions)
    auto-loading of the following files that are placed in the AviSynth autoload
    folder:
    <ul>
      <li>All AviSynth plugins (files with <tt>.dll</tt> extension).</li>
      <li>All AviSynth include scripts (files with <tt>.avsi</tt> extension).</li>
    </ul>
  </li>
</ul>
<dl>
  <dd>During auto-loading:
    <ul>
      <li>The plugin and script functions are registered in the internal data
        structures of AviSynth; all plugins are unloaded after this phase. Only
        if a function is actually used inside the script, the plugin is loaded
        again.</li>
      <li>Avisynth include scripts are parsed (executed), as if they where all
        included in the top of the script source code with <a href="corefilters/import.htm" title="Import">Import</a>
        statements.</li>
    </ul>
  </dd>
</dl>
<a name="The_script_loading_and_parsing_phase"></a>
<h3><span class="mw-headline">The script loading and parsing phase</span></h3>
<p>During this phase the following events occur:</p>
<ul>
  <li>The host video application (the editor or the encoder) requests a frame
    from the AVI stream object (usually frame 0, but you should not count on
    this always being true).</li>
  <li>The script is loaded with a call to the Import <a href="syntax_internal_functions.htm" title="Internal functions">internal
    function</a> and its contents are passed to the Eval() <a href="syntax_internal_functions_control.htm" title="Internal functions/Control functions">control
    function</a> for parsing.</li>
  <li>The entire parse process takes place. <a href="syntax_ref.htm" title="AviSynth Syntax">Expressions</a>
    are evaluated, <a href="syntax_script_variables.htm" title="Script variables">variables</a>
    are set and clips are created and chained together to form the script's
    fitler graph (see next section).</li>
  <li>At this point, just after the end of the parse process:
    <ul>
      <li>The filter graph has been formed.</li>
      <li>Global variables have attained their final (regarding the parsing
        phase) values and, along with all functions defined in the script or
        imported in the global scope, are available for use and possibly <b>modification</b>
        by the runtime scripts.</li>
    </ul>
  </li>
</ul>
<a name="The_video_frames_serving_phase"></a>
<h3><span class="mw-headline">The video frames serving phase</span></h3>
<p>During this phase the following events occur:</p>
<ul>
  <li>The initially requested frame is delivered to the host application. This
    forces runtime scripts that are possibly included in the source code to be
    parsed (executed) for that frame.</li>
  <li>The host video application requests additional frames. Each frame is
    delivered, possibly forcing runtime scripts that are in the filter chain for
    that frame to be parsed (executed).</li>
</ul>
<p><b>Note:</b> since runtime scripts may be anywhere in the filter chain and
frames may be shuffled (AviSynth is an NLE after all!) the statement &quot;for
that frame&quot; should be interpreted as &quot;for that frame of the final clip
and any linked frames of intermediate clips&quot;.</p>
<hr>
<p>Back to the <a href="script_ref_execution_model.htm" title="The script execution model">script
execution model</a>.</p>
<p><kbd>$Date: 2010/11/28 18:47:26 $</kbd></p>
</body>
</html>
